<?php
declare(strict_types=1);

namespace app\admin\model;

use app\common\support\Password;
use app\common\support\Tree;
use think\model\concern\SoftDelete;

class Menus extends Base
{
    use SoftDelete;
    const TYPE_ROUTE = 1;
    const TYPE_LINK = 2;
    const TYPE_IFRAME = 3;
    const TYPE_PAGE = 4;
    public static function getType(): array
    {
        return [
            self::TYPE_ROUTE => '路由',
            self::TYPE_LINK => '链接',
            self::TYPE_IFRAME => 'iframe',
            self::TYPE_PAGE => '页面',
        ];
    }
    protected $name = 'system_menus';
    protected $deleteTime = 'delete_time';

    /**
     * 获取菜单并转为树形结构
     * @return array
     */
    public static function getMenusOnTree()
    {
        $data = self::field('id as value,parent_id,title as label')->select()->toArray();
        $Tree = new Tree();
        $Tree->withConfig('idKey', 'value');
        $Tree->withConfig('buildChildKey', 'children');
        $Tree->withData($data);
        $TreeData = $Tree->build();

        return $TreeData;
    }
}
